<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">-->
    <el-form ref="queryForm" :model="queryParams" label-width="89px" v-show="showSearch" class="ele-form-search" @keyup.enter.native="reload"
             @submit.native.prevent>
      <el-row :gutter="15">
        <el-col :lg="8" :md="12">
<!--    <el-form-item label="编号" prop="number">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.number"-->
          <!--          placeholder="请输入编号"-->
          <!--          clearable-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
        </el-col>
        <el-col :lg="8" :md="12">
<!--      <el-form-item label="产品编码" prop="materialCode">-->
<!--        <el-input-->
<!--          v-model="queryParams.materialCode"-->
<!--          placeholder="请输入产品编码"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
        </el-col>
        <el-col :lg="8" :md="12">
      <el-form-item label="产品名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入产品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12">
      <el-form-item label="库位编号" prop="materialNumber">
        <el-input
          v-model="queryParams.materialNumber"
          placeholder="请输入库位编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12">
      <el-form-item label="库区编号" prop="reservoirNumber">
        <el-input
          v-model="queryParams.reservoirNumber"
          placeholder="请输入库区编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12">
      <el-form-item label="仓库编号" prop="warehouseNumber">
        <el-input
          v-model="queryParams.warehouseNumber"
          placeholder="请输入仓库编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12">
      <el-form-item label="批次" prop="batchNumber">
        <el-input
          v-model="queryParams.batchNumber"
          placeholder="请输入批次"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
        </el-col>
        <el-col :lg="8" :md="12">
<!--      <el-form-item label="库存数量" prop="nventoryQuantity">-->
<!--        <el-input-->
<!--          v-model="queryParams.nventoryQuantity"-->
<!--          placeholder="请输入库存数量"-->
<!--          clearable-->
<!--          @input="aa"-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
        </el-col>
        <el-col :lg="8" :md="12">
<!--      <el-form-item label="单位" prop="unit">-->
<!--        <el-input-->
<!--          v-model="queryParams.unit"-->
<!--          placeholder="请输入单位"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
        </el-col>
        <el-col :lg="8" :md="12">
<!--      <el-form-item label="库存状态" prop="stockStatus">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.stockStatus"-->
          <!--          placeholder="请输入库存状态"-->
          <!--          clearable-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--        </el-col>-->
          <!--        <el-col :lg="8" :md="12">-->
          <!--      <el-form-item label="生产日期" prop="productionDate">-->
          <!--        <el-date-picker clearable-->
          <!--                        v-model="queryParams.productionDate"-->
          <!--                        type="date"-->
          <!--                        value-format="yyyy-MM-dd"-->
          <!--                        placeholder="请选择生产日期">-->
          <!--        </el-date-picker>-->
          <!--      </el-form-item>-->
          <!--        </el-col>-->
          <!--        <el-col :lg="8" :md="12">-->
          <!--      <el-form-item label="有效天数" prop="validDays">-->
          <!--        <el-input-->
          <!--          v-model="queryParams.validDays"-->
          <!--          placeholder="请输入有效天数"-->
          <!--          clearable-->
          <!--          @input="cc"-->
          <!--          @keyup.enter.native="handleQuery"-->
          <!--        />-->
          <!--      </el-form-item>-->
          <!--        </el-col>-->
          <!--        <el-col :lg="8" :md="12">-->
          <!--      <el-form-item label="有效日期" prop="validity">-->
          <!--        <el-date-picker clearable-->
          <!--                        v-model="queryParams.validity"-->
          <!--                        type="date"-->
          <!--                        value-format="yyyy-MM-dd"-->
          <!--                        placeholder="请选择有效日期">-->
          <!--        </el-date-picker>-->
          <!--      </el-form-item>-->
        </el-col>
        <el-col :lg="8" :md="12">
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="primary"-->
<!--          plain-->
<!--          icon="el-icon-plus"-->
<!--          size="mini"-->
<!--          @click="handleAdd"-->
<!--          v-hasPermi="['wareManagement:inventoryQueryChecked:add']"-->
<!--        >新增-->
<!--        </el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="success"-->
<!--          plain-->
<!--          icon="el-icon-edit"-->
<!--          size="mini"-->
<!--          :disabled="single"-->
<!--          @click="handleUpdate"-->
<!--          v-hasPermi="['wareManagement:inventoryQueryChecked:edit']"-->
<!--        >修改-->
<!--        </el-button>-->
<!--      </el-col>-->
<!--      <el-col :span="1.5">-->
<!--        <el-button-->
<!--          type="danger"-->
<!--          plain-->
<!--          icon="el-icon-delete"-->
<!--          size="mini"-->
<!--          :disabled="multiple"-->
<!--          @click="handleDelete"-->
<!--          v-hasPermi="['wareManagement:inventoryQueryChecked:remove']"-->
<!--        >删除-->
<!--        </el-button>-->
<!--      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['wareManagement:inventoryQueryChecked:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="inventoryQueryCheckedList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="待检库存查询id" align="center" prop="checkedId" />-->
      <el-table-column label="编号" align="center" prop="number"/>
      <el-table-column label="产品编码" align="center" prop="materialCode"/>
      <el-table-column label="产品名称" align="center" prop="materialName"/>
      <el-table-column label="库位编号" align="center" prop="materialNumber"/>
      <el-table-column label="库区编号" align="center" prop="reservoirNumber"/>
      <el-table-column label="仓库编号" align="center" prop="warehouseNumber"/>
      <el-table-column label="批次" align="center" prop="batchNumber"/>
      <el-table-column label="库存数量" align="center" prop="nventoryQuantity"/>
      <el-table-column label="单位" align="center" prop="unit"/>
      <el-table-column label="库存状态" align="center" prop="stockStatus"/>
      <el-table-column label="生产日期" align="center" prop="productionDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.productionDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="有效天数" align="center" prop="validDays"/>
      <el-table-column label="有效日期" align="center" prop="validity" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.validity, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
<!--      <el-table-column fixed="right" label="操作" align="center" class-name="small-padding fixed-width" width="120">-->
<!--        <template slot-scope="scope">-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-edit"-->
<!--            @click="handleUpdate(scope.row)"-->
<!--            v-hasPermi="['wareManagement:inventoryQueryChecked:edit']"-->
<!--          >修改-->
<!--          </el-button>-->
<!--          <el-button-->
<!--            size="mini"-->
<!--            type="text"-->
<!--            icon="el-icon-delete"-->
<!--            @click="handleDelete(scope.row)"-->
<!--            v-hasPermi="['wareManagement:inventoryQueryChecked:remove']"-->
<!--          >删除-->
<!--          </el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改待检库存查询对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">

        <!--        布局-->
        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="编号" prop="number">
                <el-input v-model="form.number" placeholder="请输入编号"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-form-item label="产品编码" prop="materialCode">
                <el-input v-model="form.materialCode" placeholder="请输入产品编码"/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="产品名称" prop="materialName">
                <el-input v-model="form.materialName" placeholder="请输入产品名称"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-form-item label="库位编号" prop="materialNumber">
                <el-input v-model="form.materialNumber" placeholder="请输入库位编号"/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="库区编号" prop="reservoirNumber">
                <el-input v-model="form.reservoirNumber" placeholder="请输入库区编号"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-form-item label="仓库编号" prop="warehouseNumber">
                <el-input v-model="form.warehouseNumber" placeholder="请输入仓库编号"/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="批次" prop="batchNumber">
                <el-input v-model="form.batchNumber" placeholder="请输入批次"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-form-item label="库存数量" prop="nventoryQuantity">
                <el-input  @input="bb" v-model="form.nventoryQuantity" placeholder="请输入库存数量"/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="单位" prop="unit">
                <el-input v-model="form.unit" placeholder="请输入单位"/>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-form-item label="库存状态" prop="stockStatus">
                <el-input v-model="form.stockStatus" placeholder="请输入库存状态"/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="生产日期" prop="productionDate">
                <el-date-picker clearable
                                v-model="form.productionDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择生产日期">
                </el-date-picker>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light">
              <el-form-item label="有效天数" prop="validDays">
                <el-input @input="dd" v-model="form.validDays" placeholder="请输入有效天数"/>
              </el-form-item>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <div class="grid-content bg-purple">
              <el-form-item label="有效日期" prop="validity">
                <el-date-picker clearable
                                v-model="form.validity"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择有效日期">
                </el-date-picker>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="grid-content bg-purple-light"></div>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listInventoryQueryChecked,
  getInventoryQueryChecked,
  delInventoryQueryChecked,
  addInventoryQueryChecked,
  updateInventoryQueryChecked
} from "@/api/wareManagement/inventoryQueryChecked";

export default {
  name: "InventoryQueryChecked",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 待检库存查询表格数据
      inventoryQueryCheckedList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        number: null,
        materialCode: null,
        materialName: null,
        materialNumber: null,
        reservoirNumber: null,
        warehouseNumber: null,
        batchNumber: null,
        nventoryQuantity: null,
        unit: null,
        stockStatus: null,
        productionDate: null,
        validDays: null,
        validity: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        materialCode: [
          {required: true, message: "产品编码不能为空", trigger: "blur"}
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    aa(value){
      this.queryParams.nventoryQuantity = value.replace(/\D/g, '');
    },
    bb(value){
      this.form.nventoryQuantity = value.replace(/\D/g, '');
    },
    cc(value){
      this.queryParams.validDays = value.replace(/\D/g, '');
    },
    dd(value){
      this.form.validDays = value.replace(/\D/g, '');
    },

    /** 查询待检库存查询列表 */
    getList() {
      this.loading = true;
      listInventoryQueryChecked(this.queryParams).then(response => {
        this.inventoryQueryCheckedList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        checkedId: null,
        number: null,
        materialCode: null,
        materialName: null,
        materialNumber: null,
        reservoirNumber: null,
        warehouseNumber: null,
        batchNumber: null,
        nventoryQuantity: null,
        unit: null,
        stockStatus: null,
        productionDate: null,
        validDays: null,
        validity: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.checkedId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加待检库存查询";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const checkedId = row.checkedId || this.ids
      getInventoryQueryChecked(checkedId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改待检库存查询";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.checkedId != null) {
            updateInventoryQueryChecked(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInventoryQueryChecked(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const checkedIds = row.checkedId || this.ids;
      this.$modal.confirm('是否确认删除待检库存查询编号为"' + checkedIds + '"的数据项？').then(function () {
        return delInventoryQueryChecked(checkedIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wareManagement/inventoryQueryChecked/export', {
        ...this.queryParams
      }, `inventoryQueryChecked_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
